package com.webserver.controller;

import com.webserver.http.HttpRequest;
import com.webserver.http.HttpResponse;
import qrcode.QRCodeUtil;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * 工具相关
 *
 */
public class ToolsController {

    /**
     *  * 生成二维码
     * @param request
     * @param response
     */
    public void createQR(HttpRequest request, HttpResponse response){
        System.out.println("开始生成二维码...");
        String content = request.getParameter("content");
        System.out.println(content);

        try {
            QRCodeUtil.encode(content, response.getOutputStream());
            response.setContentType("image/jpg");
            System.out.println("生成完毕");
        } catch (Exception e) {
            e.printStackTrace();
        }


        System.out.println("二维码生成完毕");

    }

    public static void main(String[] args) {
//        String str = "https://v.youku.com/v_show/id_XMzY2OTA1NzQwOA==.html?spm=a2h1n.8261147.0.0&s=cc006a74962411de83b1";
        String str = "./1628854492(1).jpg";
        try {
            FileOutputStream fos = new FileOutputStream("qr1.jpg");
                QRCodeUtil.encode(str,fos);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (Exception e) {
        e.printStackTrace();
    }
        System.out.println("执行完毕");
    }
}
